package com.wysql.ascost.service;

import com.wysql.ascost.common.base.BaseService;
import com.wysql.ascost.common.support.ConvertUtil;
import com.wysql.ascost.mapper.auto.SysInterUrlMapper;
import com.wysql.ascost.model.auto.SysInterUrl;
import com.wysql.ascost.model.auto.SysInterUrlExample;
import com.wysql.ascost.model.custom.Tablepar;
import com.wysql.ascost.util.SnowflakeIdWorker;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 拦截url表 SysInterUrlService
 *
 * @author fuce_自动生成
 * @Title: SysInterUrlService.java
 * @Package com.wysql.ascost.service
 * @email 115889198@qq.com
 * @date 2020-01-05 01:48:22
 **/
@Service
@RequiredArgsConstructor
public class SysInterUrlService implements BaseService<SysInterUrl, SysInterUrlExample> {
    private final SysInterUrlMapper sysInterUrlMapper;


    /**
     * 分页查询
     *
     * @return
     */
    public PageInfo<SysInterUrl> list(Tablepar tablepar, String name) {
        SysInterUrlExample testExample = new SysInterUrlExample();
        testExample.setOrderByClause("id ASC");
        if (name != null && !"".equals(name)) {
            testExample.createCriteria().andInterNameLike("%" + name + "%");
        }

        PageHelper.startPage(tablepar.getPage(), tablepar.getLimit());
        List<SysInterUrl> list = sysInterUrlMapper.selectByExample(testExample);
        PageInfo<SysInterUrl> pageInfo = new PageInfo<SysInterUrl>(list);
        return pageInfo;
    }

    @Override
    public int deleteByPrimaryKey(String ids) {

        List<String> lista = ConvertUtil.toListStrArray(ids);
        SysInterUrlExample example = new SysInterUrlExample();
        example.createCriteria().andIdIn(lista);
        return sysInterUrlMapper.deleteByExample(example);


    }


    @Override
    public SysInterUrl selectByPrimaryKey(String id) {

        return sysInterUrlMapper.selectByPrimaryKey(id);

    }


    @Override
    public int updateByPrimaryKeySelective(SysInterUrl record) {
        return sysInterUrlMapper.updateByPrimaryKeySelective(record);
    }


    /**
     * 添加
     */
    @Override
    public int insertSelective(SysInterUrl record) {

        //添加雪花主键id
        record.setId(SnowflakeIdWorker.getUUID());


        return sysInterUrlMapper.insertSelective(record);
    }


    @Override
    public int updateByExampleSelective(SysInterUrl record, SysInterUrlExample example) {

        return sysInterUrlMapper.updateByExampleSelective(record, example);
    }


    @Override
    public int updateByExample(SysInterUrl record, SysInterUrlExample example) {

        return sysInterUrlMapper.updateByExample(record, example);
    }

    @Override
    public List<SysInterUrl> selectByExample(SysInterUrlExample example) {

        return sysInterUrlMapper.selectByExample(example);
    }


    @Override
    public long countByExample(SysInterUrlExample example) {

        return sysInterUrlMapper.countByExample(example);
    }


    @Override
    public int deleteByExample(SysInterUrlExample example) {

        return sysInterUrlMapper.deleteByExample(example);
    }

    /**
     * 检查name
     *
     * @param sysInterUrl
     * @return
     */
    public int checkNameUnique(SysInterUrl sysInterUrl) {
        SysInterUrlExample example = new SysInterUrlExample();
        example.createCriteria().andInterNameEqualTo(sysInterUrl.getInterName());
        List<SysInterUrl> list = sysInterUrlMapper.selectByExample(example);
        return list.size();
    }


}
